#include <iostream>
#include <iomanip>
#include <limits>
#include <string>

#include "calc.h"

using namespace std;

/** A working example.
 * This wrapper forwards user input from stdin, line by line, to the calculator.
 * The returned result, or the cause of processing failure, is printed on stdout
 */
int main() {
  // (try to) load parsers. It is up to calc what parsers are loaded, and there
  // is currently no 
  try {
    Calc::loadParsers();
  } catch(exception &e) {
    cout << "Error loading parsers: " << e.what();
    return 1;
  }

  // Friendly prompt
  cout << "Enter math formula or '^D' to exit" << endl;

  string input = "";

  // Read and process lines one by one
  while(getline(cin, input)) {
    Calc calc(input);
    if (calc.parse()) { // successful
      cout << "Result: " << setprecision(28) << calc.getResult() << endl;
    } else {
      cout << "Processing error: " << calc.getMessage() << endl;
    } 
  }

  input = "";

  return 0;
} 
